<template>
  <div>
    <el-dialog title="新增往来单位" :visible.sync="dialogVisible" lock-scroll width="60%">
      <div class="dialog_div_new">
        <div class="dialog_middle">
          <div class="input_line">
            <div>
              <p>单位名称</p>
              <input type="text" ref="nameRef" @focusout="getNameToPinying" v-model="receiveData.ruleForm.dwmc" />
            </div>
            <div>
              <p>联系人</p>
              <input type="text" v-model="receiveData.ruleForm.lxr" />
            </div>
          </div>
          <div class="input_line">
            <div>
              <p>单位性质</p>
              <el-select v-model="receiveData.ruleForm.dwxz">
                <el-option
                  v-for="item in CompanyNatureOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div>
              <p>联系电话</p>
              <input type="text" v-model="receiveData.ruleForm.lxdh" />
            </div>
          </div>
          <div class="input_line">
            <div>
              <p>拼音编码</p>
              <input type="text" ref="nameRef" v-model="receiveData.ruleForm.pym" />
            </div>
            <div>
              <p>手机</p>
              <input type="text" v-model="receiveData.ruleForm.sj" />
            </div>
          </div>
          <div class="input_line">
            <div class="line_dialog">
              <p>单位类别</p>
              <p class="dialog_input">
                <el-select
                  v-model="receiveData.ruleForm.dwlb"
                  filterable
                  allow-create
                  default-first-option
                  placeholder="请选择单位类别"
                >
                  <el-option v-for="item in dwlbOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                  <el-option value>
                    <div @click="onShowNewTree" style="display: flex; justify-content: center">
                      <span><i class="el-icon-plus"></i>新增</span>
                    </div>
                  </el-option>
                </el-select>
                <i class="el-icon-more"></i>
              </p>
            </div>
            <div>
              <p>所属业务</p>
              <input type="text" v-model="receiveData.ruleForm.ssyw" />
            </div>
          </div>
          <div class="input_line">
            <div class="line_areaAddress">
              <p>行政区划</p>
              <div>
                <input disabled class="address_china" type="text" value="中国" />
                <el-cascader
                  size="large"
                  placeholder="请选择省/市/县区"
                  :options="ssqOptions"
                  v-model="selectedOptions"
                  @change="addressChange"
                >
                </el-cascader>
              </div>
            </div>
            <div class="line_detailedAddress">
              <p>详细地址</p>
              <input type="text" v-model="receiveData.ruleForm.dz" />
              <el-button type="primary">识别</el-button>
            </div>
          </div>
          <div class="input_line">
            <div>
              <p>预设售价</p>
              <el-select v-model="receiveData.ruleForm.yssj">
                <el-option v-for="item in PresetPriceOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
            <div>
              <p>预设折扣</p>
              <el-select v-model="receiveData.ruleForm.yszk">
                <el-option
                  v-for="item in PresetDiscountOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="input_switch">
            <div>
              <p>开票信息</p>
              <el-switch v-model="receiveData.ruleForm.kpxx" active-color="#1A93FA" inactive-color="#D3D2D2">
              </el-switch>
            </div>
          </div>
          <div v-show="receiveData.ruleForm.kpxx" class="input_line">
            <div>
              <p>开户银行</p>
              <input type="text" v-model="receiveData.ruleForm.khyh" />
            </div>
            <div>
              <p>银行账户</p>
              <input type="text" v-model="receiveData.ruleForm.yhzh" />
            </div>
          </div>
          <div v-show="receiveData.ruleForm.kpxx" class="input_line">
            <div>
              <p>银行账号</p>
              <input type="text" ref="nameRef" v-model="receiveData.ruleForm.yhzh1" />
            </div>
            <div>
              <p>企业税号</p>
              <input type="text" v-model="receiveData.ruleForm.sh" />
            </div>
          </div>
          <div v-show="receiveData.ruleForm.kpxx" class="input_line">
            <div>
              <p>开票地址</p>
              <input type="text" v-model="receiveData.ruleForm.kpdz" />
            </div>
            <div>
              <p>电话</p>
              <input type="text" v-model="receiveData.ruleForm.dh" />
            </div>
          </div>
          <div class="input_switch">
            <div>
              <p>应收应付</p>
              <el-switch v-model="receiveData.ruleForm.ysyf" active-color="#1A93FA" inactive-color="#D3D2D2">
              </el-switch>
              <span>注：期初应收应付首次录入后，开单后不可修改，后期可通过调整单的方式调整期初应收应付。</span>
            </div>
          </div>
          <div v-show="receiveData.ruleForm.ysyf" class="input_line">
            <div>
              <p>期初应收款</p>
              <input type="text" v-model="receiveData.ruleForm.qcysk" />
            </div>
            <div>
              <p>期初应付款</p>
              <input type="text" v-model="receiveData.ruleForm.qcyfk" />
            </div>
          </div>
          <div v-show="receiveData.ruleForm.ysyf" class="input_line">
            <div>
              <p>累计应收款</p>
              <input disabled type="text" style="background: #ededed" v-model="receiveData.ruleForm.ljysk" />
            </div>
            <div>
              <p>累计应付款</p>
              <input disabled type="text" style="background: #ededed" v-model="receiveData.ruleForm.ljyfk" />
            </div>
          </div>
          <div v-show="receiveData.ruleForm.ysyf" class="input_line">
            <div>
              <p>应收信用额</p>
              <input type="text" v-model="receiveData.ruleForm.ysxyed" />
            </div>
            <div>
              <p>应付信用额</p>
              <input type="text" v-model="receiveData.ruleForm.yfxyed" />
            </div>
          </div>
          <div v-show="receiveData.ruleForm.ysyf" class="input_line">
            <div>
              <p>收款期限(天)</p>
              <input type="text" v-model="receiveData.ruleForm.skqx" />
            </div>
            <div>
              <p>付款期限(天)</p>
              <input type="text" v-model="receiveData.ruleForm.fkqx" />
            </div>
          </div>

          <div class="input_textarea">
            <p>备注</p>
            <textarea rows="5" cols="5" v-model="receiveData.ruleForm.remarks"></textarea>
          </div>
        </div>
        <div class="dialog_bottom">
          <el-button type="primary" @click.stop="onAddSubmit">保存</el-button>
          <el-button @click.stop="dialogVisible = false">取消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { regionData, CodeToText } from 'element-china-area-data'
export default {
  props: {
    receiveData: Object,
  },
  data() {
    return {
      dialogVisible: true,
      ssqOptions: regionData, //省市区选项
      selectedOptions: [], //省市区
      // 单位性质
      CompanyNatureOptions: [
        {
          value: '供应商',
          label: '供应商',
        },
        {
          value: '自主研发',
          label: '自主研发',
        },
      ],
      // 单位类别
      dwlbOptions: [
        {
          value: '广东供应商',
          label: '广东供应商',
        },
        {
          value: '山西供应商',
          label: '山西供应商',
        },
      ],
      // 预设售价
      PresetPriceOptions: [
        {
          value: '一百',
          label: '一百',
        },
        {
          value: '二百',
          label: '二百',
        },
        {
          value: '三百',
          label: '三百',
        },
        {
          value: '四百',
          label: '四百',
        },
      ],
      // 预设折扣
      PresetDiscountOptions: [
        {
          value: '九九折',
          label: '九九折',
        },
        {
          value: '八八折',
          label: '八八折',
        },
        {
          value: '七七折',
          label: '七七折',
        },
        {
          value: '六六折',
          label: '六六折',
        },
      ],
    }
  },
  methods: {
    // 获取省市区数据
    addressChange(arr) {
      this.receiveData.ruleForm.dz = CodeToText[arr[arr.length - 1]]
    },
    // 转换拼音码
    getNameToPinying(event) {
      this.receiveData.ruleForm.pym = this.$pinyin.getJp(event.target.value)
    },
    onShowNewTree(){
        this.$emit('onShowNewTree')
    },
    onAddSubmit(){
        this.dialogVisible = !this.dialogVisible
        this.$emit('onAddSubmit',this.receiveData)
    }
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  .el-dialog__body {
    padding: 0;
  }
  .el-dialog__header {
    width: 100%;
    height: 0.937559rem;
    box-sizing: border-box;
    padding: 0 0.375023rem;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    span {
      font-size: 0.300019rem;
      color: #666;
      font-weight: 600;
    }
    .el-dialog__headerbtn {
      position: static;
      .el-icon-close {
        color: #999;
        font-size: 0.48753rem;
      }
    }
  }
}
.dialog_div_new {
  width: 100%;
  height: 60vh;
  overflow: auto;
  background: #fff;
  .dialog_middle {
    height: calc(100% - 1.12507rem);
    margin-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
    padding: 0 0.375023rem;
    overflow: auto;
    div {
      p {
        margin: 0;
        width: 1.312582rem;
        display: flex;
        font-size: 0.225rem;
        font-family: PingFang SC;
        font-weight: 400;
        color: #666666;
        opacity: 1;
      }
      input {
        flex: 1;
        height: 30px;
        background: #ffffff;
        border: 1px solid #e3e3e3;
        opacity: 1;
        border-radius: 4px;
        font-size: 0.225014rem;
        color: #666;
        box-sizing: border-box;
        padding: 0 0.187512rem;
        &:focus {
          outline: none;
          border-color: #1890ff;
        }
      }
      ::v-deep .el-select {
        margin-left: 0 !important;
        flex: 1;
        .el-input {
          .el-input__inner {
            height: 30px;
            background: #ffffff;
            border: 1px solid #e3e3e3;
            opacity: 1;
            border-radius: 4px;
            font-size: 0.225014rem;
            color: #666;
            box-sizing: border-box;
            padding: 0 0.187512rem;
          }
          .el-input__suffix {
            height: 0.562535rem;
            display: flex;
            align-items: center;
          }
        }
      }
    }
    .input_line {
      display: flex;
      height: 0.562535rem;
      margin-top: 0.281268rem;
      div {
        flex: 1;
        display: flex;
        align-items: center;
        &:first-child {
          margin-right: 0.187512rem;
        }
        &:last-child {
          margin-left: 0.187512rem;
        }
      }
      .line_dialog {
        width: 100%;
        .dialog_input {
          flex: 1;
          position: relative;
          display: flex;
          align-items: center;
          justify-content: flex-end;
          ::v-deep .el-select {
            margin-right: 0;
            .el-select-dropdown__item {
              p {
                margin: 0;
              }
            }
            i {
              display: none;
            }
          }
          i {
            position: absolute;
            margin-right: 0.187512rem;
            color: #bfbfbf;
            font-size: 0.281268rem;
            cursor: pointer;
          }
        }
      }
      .line_areaAddress {
        div {
          height: 0.562535rem;
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-left: 0;
          .address_china {
            flex: 0;
            width: 0.937559rem;
            height: 0.562535rem;
            text-align: center;
          }
          ::v-deep .el-cascader {
            flex: 1;
            margin-left: 0.187512rem;
            height: 0.562535rem;
            .el-input {
              display: flex;
              align-items: center;
              .el-input__inner {
                height: 0.562535rem;
              }
              .el-input__suffix {
                height: 0.562535rem;
                display: flex;
                align-items: center;
              }
            }
          }
        }
      }
      .line_detailedAddress {
        ::v-deep .el-button {
          width: 0.750047rem;
          height: 0.562535rem;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 0.225014rem;
          margin-left: 0.093756rem;
          background: #1890ff;
        }
      }
    }

    .input_switch {
      display: flex;
      height: 0.562535rem;
      margin-top: 0.281268rem;
      div {
        flex: 1;
        display: flex;
        align-items: center;
        margin-right: 0.375023rem;
        ::v-deep .el-switch {
          flex: 0;
          .el-switch__core {
            width: 0.562535rem;
            height: 0.31877rem;
          }
          .el-switch__core:after {
            width: 0.281268rem;
            height: 0.281268rem;
            top: 0;
          }
          .is-checked .el-switch__core::after {
            margin-left: 0.281268rem !important;
          }
        }
        ::v-deep .el-switch.is-checked .el-switch__core::after {
          left: 100%;
          margin-left: -15px;
        }
        span {
          color: #fd6c21;
          font-size: 0.225014rem;
          margin-left: 0.562535rem;
        }
      }
    }
    .input_textarea {
      display: flex;
      align-items: flex-start;
      margin-top: 0.281268rem;
      textarea {
        flex: 1;
        background: #ffffff;
        border: 1px solid #e3e3e3;
        opacity: 1;
        border-radius: 4px;
        font-size: 0.225014rem;
        color: #666;
        box-sizing: border-box;
        padding: 0.187512rem;
        &:focus {
          outline: none;
          border-color: #1890ff;
        }
      }
    }
  }
  .dialog_bottom {
    width: 100%;
    height: 1.12507rem;
    box-sizing: border-box;
    padding: 0 0.187512rem;
    display: flex;
    align-items: center;
    justify-content: center;
    ::v-deep .el-button {
      width: 1.12507rem;
      height: 0.562535rem;
      text-align: center;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.225014rem;
      border-radius: 0.093756rem;
      background: #fff;
      border: 1px solid #dddddd;
      color: #666666;
    }
    ::v-deep .el-button--primary {
      background: #1890ff;
      border-color: #1890ff;
      color: #fff;
      margin-right: 0.112507rem;
    }
    ::v-deep .el-button--default {
      margin-left: 0.112507rem;
    }
  }
}
</style>